import './member_info_item_model.dart';

class MemberGroup {
  final int id;
  String? groupName;
  List<MemberItem>? memberList;

  MemberGroup({
    required this.id,
    this.groupName,
    this.memberList,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'groupName': groupName,
      'memberList': memberList?.map((member) => member.toJson()).toList(),
    };
  }

  factory MemberGroup.fromJson(Map<String, dynamic> json) {
    return MemberGroup(
      id: json['id'] as int,
      groupName: json['groupName'],
      memberList: json['memberList'] != null
          ? (json['memberList'] as List)
              .map((item) => MemberItem.fromJson(item))
              .toList()
          : null,
    );
  }
}

class MemberItem {
  final int id;
  List<MemberInfoItem>? memberInfoList;
  bool choose;


  List<String> get valueAList => memberInfoList
      ?.where((e) => e.type == 'A' || e.type == 'AB')
      .map((e) => e.value ?? '')
      .toList() ?? [];
  List<String> get valueBList => memberInfoList
      ?.where((e) => e.type == 'B')
      .map((e) => e.value ?? '')
      .toList() ?? [];

  MemberItem({
    required this.id,
    this.memberInfoList,
    this.choose = false,
  });

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'memberInfoList': memberInfoList?.map((info) => info.toJson()).toList(),
      'choose': choose,
    };
  }

  factory MemberItem.fromJson(Map<String, dynamic> json) {
    return MemberItem(
      id: json['id'] as int,
      memberInfoList: json['memberInfoList'] != null
          ? (json['memberInfoList'] as List)
              .map((item) => MemberInfoItem.fromJson(item))
              .toList()
          : null,
      choose: json['choose'] ?? false,
    );
  }
}
  